package com.pilhun.parser.run;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

import com.pilhun.parser.BeanFactory;
import com.pilhun.parser.GenericXmlApplicationContext;
import com.pilhun.parser.GenericXmlApplicationContextImpl;
import com.pilhun.parser.ParserTypes;
import com.pilhun.parser.XmlBeanDefinitionReaderImpl;

public class App 
{
	private static final String FILE_PATH ="src\\main\\java\\com\\pilhun\\parser\\resources\\Context.xml";
	static String readFile(String path, Charset encoding) throws IOException {
		  byte[] encoded = Files.readAllBytes(Paths.get(path));
		  return new String(encoded, encoding);
	}
	
	
    public static void main( String[] args )
    {
		XmlBeanDefinitionReaderImpl parser = new XmlBeanDefinitionReaderImpl(StandardCharsets.UTF_8);
		GenericXmlApplicationContext gen = new GenericXmlApplicationContextImpl(parser);
		gen.load(FILE_PATH);
		gen.setParserType(ParserTypes.DOM);
		BeanFactory factory = gen.getBeanFactory();
		GreetingServiceImpl bean = factory.getBean("greetingService", GreetingServiceImpl.class);
		bean.greet();
    }
}
